/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/07/12
*/
#include "Log.h"
#include "../core/Base.h"

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

EDUI_NAMESPACE_BEGIN

void Log(const char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    vprintf(fmt, args);
    printf("\n");
    va_end(args);
}

void Log(const Rect* rc, const char* msg)
{
    if (!rc) printf("Error! Rect is null.");
    else printf("Rect-> x:%d,y:%d,w:%d,h:%d", rc->x, rc->y, rc->w, rc->h);

    if (msg) printf(" msg:%s\n", msg);
    else printf(" msg:\n");
}

void Logf(const char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    vprintf(fmt, args);
    va_end(args);
}

void LogDebug(const char *fmt, ...)
{
#ifdef DEBUG
    va_list args;
    va_start(args, fmt);
    vprintf(fmt, args);
    printf("\n");
    va_end(args);
#endif
}

void LogDebug(const Rect* rc, const char* msg)
{
#ifdef DEBUG
    Log(rc, msg);
#endif
}

void LogDebugf(const char *fmt, ...)
{
#ifdef DEBUG
    va_list args;
    va_start(args, fmt);
    vprintf(fmt, args);
    va_end(args);
#endif
}

void _EDUI_Assert(const char* exp, const char* file, int line, const char* fun, const char *fmt, ...)
{
    char msg[100] = "no message.";
    if (fmt){
        va_list args;
        va_start(args, fmt);
        vsprintf(msg, fmt, args);
        va_end(args);
    }

    Log("***************************************************");
    Log("[EDUI] Assert failed: %s", exp);
    Log("[EDUI]       in file: %s %d", file, line);
    Log("[EDUI]      function: %s", fun);
    Log("[EDUI]       message: %s", msg);
    Log("**************************************************");
    
#ifdef DEBUG
    abort();
#endif
}

EDUI_NAMESPACE_END
